package maven.demo5;

/**
 * 异常的实践经验和总结
 * 1. 多重 catch 块后面，可以加一个 catch(Exception e) 处理被遗漏的异常
 * 2. 不确定的代码，也可以添加 try...catch
 * 3. 尽量处理异常，而不是简单的打印-- printStackTrace()
 * 4. 数据库链接中，尽量添加 finally 语句去释放占用的资源
 */
public class TestException {
    public static void main(String[] args) {
        TryCatchFinally test1 = new TryCatchFinally();

        int result = test1.testCircle();
        System.out.println("程序结束, 运行结果为：" + result);

        int result2 = test1.testFinally();
        System.out.println("testFinally完成，运行结果：" + result2);

        int result3 = test1.testCatchFinally();
        System.out.println("testCatchFinally完成，运行结果：" + result3);

        int result4 = test1.testFinallyReturn();
        System.out.println("testFinallyReturn完成，运行结果：" + result4);


        // exception chain -- 异常链
        ExceptionChain chainTest = new ExceptionChain();
        try {
            chainTest.testExceptionChain();
        } catch (Exception e) {
            e.printStackTrace();
        }


        // 查找图书的demo
        BookManageEasy bookFinder = new BookManageEasy();
        bookFinder.findBook();
    }

}
